<div id="content">
    <div id="page-heading"><h1>Edit Group</h1></div>
    <table border="0" width="100%" cellpadding="0" cellspacing="0" id="content-table">
        <tr>
            <th rowspan="3" class="sized">
                 <?php echo $this->Html->image('../images/shared/side_shadowleft.jpg', array('alt' => '', 'width' => '20', 'height' => '300')); ?>
            </th>
            <th class="topleft"></th>
            <td id="tbl-border-top">&nbsp;</td>
            <th class="topright"></th>
            <th rowspan="3" class="sized">
                <?php echo $this->Html->image('../images/shared/side_shadowright.jpg', array('alt' => '', 'width' => '20', 'height' => '300')); ?>
             </th>
        </tr>
        <tr>
            <td id="tbl-border-left"></td>
            <td>
                <div id="content-table-inner">
                    <table border="0" width="100%" cellpadding="0" cellspacing="0">
                        <tr valign="top">
                            <td>
                                <?php echo $this->Form->create("$sN", array('action' => 'group_edit', 'class' => 'form', 'type' => 'file')); ?>
                                <table border="0" cellpadding="0" cellspacing="0"  id="id-form">
                                <?php
                                    echo $this->Session->flash();
                                    echo $this->Form->input('Group.id');
                                ?>
                                    <script type="text/javascript">
                                        jQuery(document).ready(function(){
                                            jQuery('#role-content li input').each(function(){
                                                if(jQuery(this).attr('checked')){
                                                    jQuery(this).parent('li').addClass('selected');
                                                }
                                            });
                                            jQuery('#role-content li input').change(function(){
                                                if(jQuery(this).attr('checked')){
                                                    jQuery(this).parent('li').addClass('selected');
                                                }else{
                                                    jQuery(this).parent('li').removeClass('selected');
                                                }
                                            })
                                        });
                                        function check_all(id){
                                            jQuery('#'+id  + ' input').each(function(){
                                                jQuery(this).attr('checked',true);
                                                jQuery(this).parent('li').addClass('selected');
                                            });
                                            return false;
                                        }
                                        function uncheck_all(id){
                                            jQuery('#'+id  + ' input').each(function(){
                                                jQuery(this).attr('checked',false);
                                                jQuery(this).parent('li').removeClass('selected');
                                            });
                                            return false;
                                        }
                                    </script>
                                    <tr>
                                        <th valign="top">Name:</th>
                                        <td>
                                            <?php
                                                echo $this->Form->input('Group.name', array(
                                                                    'label'     => false,
                                                                    'div'       => false,
                                                                    'class'     => 'inp-form med')
                                                    );     
                                            ?>      
                                        </td>
                                        <td></td> 
                                    </tr>
                                    <tr>
                                        <th colspan="3">Privileges </th>
                                    </tr>
                                    <tr>
                                        <td valign="top" id="user_role" colspan="3">
                                            <div id="role-content">
                                                <?php foreach($controllers as $controler=>$actions){ ?>
                                                    <div class="custom_role" id="div_<?=$controler?>">
                                                        <h4><?=$controler?> <?php echo $this->Html->link('Check all','#',array("onClick"=>"return check_all('div_$controler')")) ?> <?php echo $this->Html->link('UnCheck all','#',array('onClick'=>"return uncheck_all('div_$controler')")) ?></h4>
                                                        <ul>
                                                            <?php 
                                                            $arr_action = array();
                                                            if(isset($this->data['Group']['data'][$controler])){
                                                                $arr_action = $this->data['Group']['data'][$controler];
                                                            }
                                                            foreach($actions as $action=>$description){ ?>
                                                            <li><input type="checkbox" <?php if(in_array($action, $arr_action)){ echo 'checked="true"'; }  ?> name="data[Group][data][<?=$controler?>][]" value="<?php echo $action ?>"/><?=$description?></li>
                                                            <?php } ?>
                                                        </ul>
                                                    </div>
                                                <?php } ?>
                                            </div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <th>&nbsp;</th>
                                        <td valign="top">
                                            <?php echo $this->Form->submit('Save', array('div'=>false,'class' => 'submit-button')); ?>
                                            <?php echo $this->Html->link('Cancel', array('controller' => $lN, 'action' => 'group', 'admin' => true), array('class' => 'cancel-button')); ?>
                                        </td>
                                        <td></td>
                                    </tr>
                                </table>
                                <?php echo $this->Form->end();?>    
                            </td>
                            <td>&nbsp;</td>
                        </tr>
                        <tr>
                            <td>
                               <?php echo $this->Html->image('../images/shared/blank.gif', array('alt' => 'blank', 'width' => '695', 'height' => '1')); ?>
                            </td>
                            <td></td>
                        </tr>
                    </table>
                    <div class="clear"></div>
                </div>
            </td>
            <td id="tbl-border-right"></td>
        </tr>
        <tr>
            <th class="sized bottomleft"></th>
            <td id="tbl-border-bottom">&nbsp;</td>
            <th class="sized bottomright"></th>
        </tr>
    </table>
    <div class="clear">&nbsp;</div>
</div>
